package cn.edu.sdjzu.xg.eagle.service.impl;

import cn.edu.sdjzu.xg.eagle.entities.Club;
import cn.edu.sdjzu.xg.eagle.mapper.ClubMapper;
import cn.edu.sdjzu.xg.eagle.service.inface.ClubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ClubImpl implements ClubService {

    @Autowired
    private ClubMapper clubMapper;

    @Override
    @Transactional
    public String addClub(Club club) {
        try {
            if (clubMapper.addClub(club)) {
                return "添加俱乐部成功";
            }
            return "添加俱乐部失败";
        } catch (Exception e) {
            throw new RuntimeException("添加俱乐部异常", e);
        }
    }

    @Override
    @Transactional
    public String deleteClub(String clubNo) {
        try {
            if (clubMapper.deleteClub(clubNo)) {
                return "删除俱乐部成功";
            } else {
                return "删除俱乐部失败，未找到对应记录";
            }
        } catch (Exception e) {
            throw new RuntimeException("删除俱乐部异常", e);
        }
    }

    @Override
    @Transactional
    public String updateClub(Club club) {
        try {
            if (clubMapper.updateClub(club)) {
                return "更新俱乐部成功";
            } else {
                return "更新俱乐部失败，未找到对应记录";
            }
        } catch (Exception e) {
            throw new RuntimeException("更新俱乐部异常", e);
        }
    }

    @Override
    public Club findClubById(String clubNo) {
        try {
            return clubMapper.findClubById(clubNo);
        } catch (Exception e) {
            throw new RuntimeException("查询俱乐部异常", e);
        }
    }

    @Override
    public List<Club> findClubs() {
        try {
            return clubMapper.findClubs();
        } catch (Exception e) {
            throw new RuntimeException("查询俱乐部列表异常", e);
        }
    }
}